{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 一.简介\n",
    "上一节已经介绍了提升树的算法流程，这一节只需要将下面的优化过程替换成求解具体的梯度即可：   \n",
    "\n",
    "$$\n",
    "w_m^*=arg\\min_{w_m}\\sum_{i=1}^NL(y_i,f_{m-1}(x_i)+T(x_i,w_m))\n",
    "$$    \n",
    "\n",
    "下面介绍一下常用的损失函数及其对应的负梯度   \n",
    "\n",
    "\n",
    "（1）损失平方误差：   \n",
    "\n",
    "$$\n",
    "\\frac{1}{2}(f_{m-1}(x)-y)^2\n",
    "$$\n",
    "\n",
    "对应的负梯度：   \n",
    "\n",
    "$$\n",
    "y-f_{m-1}(x)\n",
    "$$   \n",
    "\n",
    "（2）绝对误差损失：    \n",
    "\n",
    "$$\n",
    "\\mid f_{m-1}(x)-y \\mid\n",
    "$$\n",
    "\n",
    "对应的负梯度：   \n",
    "\n",
    "$$\n",
    "sign(y-f_{m-1}(x))\n",
    "$$   \n",
    "\n",
    "（3）Huber损失:   \n",
    "\n",
    "$$\n",
    "\\left\\{\\begin{matrix}\n",
    "\\frac{1}{2}(f_{m-1}(x)-y)^2 & \\mid y-f_{m-1}(x) \\mid < \\delta\\\\\n",
    "\\delta \\mid y-f_{m-1}(x) \\mid & otherwise\n",
    "\\end{matrix}\\right.\n",
    "$$\n",
    "\n",
    "对应的负梯度：  \n",
    "\n",
    "$$\n",
    "\\left\\{\\begin{matrix}\n",
    "y-f_{m-1}(x) & \\mid y-f_{m-1}(x) \\mid < \\delta\\\\\n",
    "\\delta\\cdot sign(y-f_{m-1}(x)) & otherwise\n",
    "\\end{matrix}\\right.\n",
    "$$   \n",
    "\n",
    "（4）分位数损失：   \n",
    "\n",
    "$$\n",
    "\\left\\{\\begin{matrix}\n",
    "\\theta\\mid y-f_{m-1}(x)\\mid &  y>f_{m-1}(x)\\\\\n",
    "(1-\\theta)\\mid y-f_{m-1}(x)\\mid  & otherwise\n",
    "\\end{matrix}\\right.\n",
    "$$   \n",
    "\n",
    "对应的负梯度：   \n",
    "\n",
    "$$\n",
    "\\left\\{\\begin{matrix}\n",
    "\\theta &  y>f_{m-1}(x)\\\\\n",
    "\\theta-1  & otherwise\n",
    "\\end{matrix}\\right.\n",
    "$$   \n",
    "\n",
    "注意： $0<\\theta<1$\n",
    "\n",
    "这四种损失函数的特点：  \n",
    "\n",
    "（1）平方误差对$>1$的错误会进行放大，所以对离群点比较敏感；  \n",
    "\n",
    "（2）而绝对误差可以避免这个问题，但在极小点附近，可能会由于梯度偏大而跨过极小点；  \n",
    "\n",
    "（3）huber损失和分位数损失主要避免异常值的影响\n",
    "\n",
    "接下来直接进行代码实现\n",
    "\n",
    "### 二.代码实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "os.chdir('../')\n",
    "from ml_models.tree import CARTRegressor\n",
    "import copy\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "\n",
    "\"\"\"\n",
    "梯度提升模型，封装到ml_models.ensemble\n",
    "\"\"\"\n",
    "\n",
    "\n",
    "class GradientBoostingRegressor(object):\n",
    "    def __init__(self, base_estimator=None, n_estimators=10, learning_rate=1.0, loss='ls', huber_threshold=1e-1,\n",
    "                 quantile_threshold=0.5):\n",
    "        \"\"\"\n",
    "        :param base_estimator: 基学习器，允许异质；异质的情况下使用列表传入比如[estimator1,estimator2,...,estimator10],这时n_estimators会失效；\n",
    "                                同质的情况，单个estimator会被copy成n_estimators份\n",
    "        :param n_estimators: 基学习器迭代数量\n",
    "        :param learning_rate: 学习率，降低后续基学习器的权重，避免过拟合\n",
    "        :param loss:表示损失函数ls表示平方误差,lae表示绝对误差,huber表示huber损失,quantile表示分位数损失\n",
    "        :param huber_threshold:huber损失阈值，只有在loss=huber时生效\n",
    "        :param quantile_threshold损失阈值，只有在loss=quantile时生效\n",
    "        \"\"\"\n",
    "        self.base_estimator = base_estimator\n",
    "        self.n_estimators = n_estimators\n",
    "        self.learning_rate = learning_rate\n",
    "        if self.base_estimator is None:\n",
    "            # 默认使用决策树桩\n",
    "            self.base_estimator = CARTRegressor(max_depth=2)\n",
    "        # 同质分类器\n",
    "        if type(base_estimator) != list:\n",
    "            estimator = self.base_estimator\n",
    "            self.base_estimator = [copy.deepcopy(estimator) for _ in range(0, self.n_estimators)]\n",
    "        # 异质分类器\n",
    "        else:\n",
    "            self.n_estimators = len(self.base_estimator)\n",
    "        self.loss = loss\n",
    "        self.huber_threshold = huber_threshold\n",
    "        self.quantile_threshold = quantile_threshold\n",
    "\n",
    "    def _get_gradient(self, y, y_pred):\n",
    "        if self.loss == 'ls':\n",
    "            return y - y_pred\n",
    "        elif self.loss == 'lae':\n",
    "            return (y - y_pred > 0).astype(int) * 2 - 1\n",
    "        elif self.loss == 'huber':\n",
    "            return np.where(np.abs(y - y_pred) > self.huber_threshold,\n",
    "                            self.huber_threshold * ((y - y_pred > 0).astype(int) * 2 - 1), y - y_pred)\n",
    "        elif self.loss == \"quantile\":\n",
    "            return np.where(y - y_pred > 0, self.quantile_threshold, self.quantile_threshold-1)\n",
    "        \n",
    "    def fit(self, x, y):\n",
    "        # 拟合第一个模型\n",
    "        self.base_estimator[0].fit(x, y)\n",
    "        y_pred = self.base_estimator[0].predict(x)\n",
    "        new_y = self._get_gradient(y, y_pred)\n",
    "        for index in range(1, self.n_estimators):\n",
    "            self.base_estimator[index].fit(x, new_y)\n",
    "            y_pred += self.base_estimator[index].predict(x) * self.learning_rate\n",
    "            new_y = self._get_gradient(y, y_pred)\n",
    "\n",
    "    def predict(self, x):\n",
    "        return np.sum(\n",
    "            [self.base_estimator[0].predict(x)] +\n",
    "            [self.learning_rate * self.base_estimator[i].predict(x) for i in\n",
    "             range(1, self.n_estimators - 1)] +\n",
    "            [self.base_estimator[self.n_estimators - 1].predict(x)]\n",
    "            , axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#构造数据\n",
    "data = np.linspace(1, 10, num=100)\n",
    "target1 = 3*data[:50] + np.random.random(size=50)*3#添加噪声\n",
    "target2 = 3*data[50:] + np.random.random(size=50)*10#添加噪声\n",
    "target=np.concatenate([target1,target2])\n",
    "data = data.reshape((-1, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x1e76c87fa20>]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3XuUXGWZ7/Hv051OUrlAJySEpMkNQ8IlgYTTKhoGNCoR8BIyjFEc5Dh6oi5HEQUNrlFcCz2JZEA9jjoniso6oqCAAcExIoHDwJEwuUJIiCjhku6QeyckdJru9HP+qKpOdXXtql332++zVq9079q192sveert533eZ5u7IyIi1a+h3AMQEZHCUEAXEakRCugiIjVCAV1EpEYooIuI1AgFdBGRGqGALiJSIxTQRURqhAK6iEiNGFTKm40ZM8anTJlSyluKiFS9devW7XX3sZnOK2lAnzJlCmvXri3lLUVEqp6ZvRTmPKVcRERqhAK6iEiNUEAXEakRCugiIjVCAV1EpEaUtMpFRKRWrNzQxvJV22jv6GRCc4Tr589gwZyWso5JAV1EJEsrN7Rxw73P0Nl9DIC2jk5uuPcZgLIGdaVcRESytHzVtr5gHtfZfYzlq7aVaURRCugiIllq7+jM6nipZEy5mNlQ4DFgSOz8u939RjP7OXARcDB26n93943FGqiISCEUIvc9oTlCW4rgPaE5Uqhh5iTMDL0LmOfu5wKzgfea2fmx165399mx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fd/XTg4djPBaeAHpK773T39bHvXyP6H2zd9vE1s1OBy4CflHss5WZmJwAXArcBuPsb7t5R3lGV1SAgYmaDgGFAe5nHU1Lu/hiwP+nwB4HbY9/fDiwoxr0V0HNgZlOAOcCa8o6krL4LfBnoLfdAKsBpwB7gZ7EU1E/MbHi5B1UO7t4G/CvwMrATOOjufyzvqCrCOHffCdHJIXByMW6igJ4lMxsB3AN8wd0PlXs85WBm7wN2u/u6co+lQgwCzgN+5O5zgCMU6U/qShfLDX8QmApMAIab2T+Wd1T1QwE9C2bWRDSY3+Hu95Z7PGU0F/iAmb0I3AnMM7NflHdIZbUD2OHu8b/Y7iYa4OvRu4Ht7r7H3buBe4G3l3lMlWCXmY0HiP27uxg3UUAPycyMaI50q7vfWu7xlJO73+Dup7r7FKILXqvdvW5nYe7+KvCKmcWfVv4uYEsZh1ROLwPnm9mw2H8z76JOF4iT3A9cHfv+auC+Ytyk6p4pWkZzgauAZ8xsY+zYV93992Uck1SOzwF3mNlg4AXg42UeT1m4+xozuxtYT7QybAN1tmPUzH4FvAMYY2Y7gBuBZcCvzewTRD/0/qEo99ZOURGR2qCUi4hIjVBAFxGpEQroIiI1QgFdRKRGKKCLiNQIBXQRkRqhgC4iUiMU0EVEasT/B9aUZODiM0OYAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1e76c8ab8d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#同质\n",
    "model=GradientBoostingRegressor(base_estimator=CARTRegressor(),n_estimators=3)\n",
    "model.fit(data,target)\n",
    "plt.scatter(data, target)\n",
    "plt.plot(data, model.predict(data), color='r')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x1e76c87f0b8>]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVB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09YK3NBhYAlwa4TcFgnzGmEUD+1/3+eIgCuoeMMQZHjnSrtXZyoNsTSNbaMdbaP1hrm+EY8FplrY3YXpi19mfgJ2NMwW7l3YEtAWxSIO0GOhpjauT/P9OdCB0gLuFdYED+9wOARf54SMjtKRpAnYAbgU3GmK/yj91vrX0/gG2S4DEcmGuMqQb8ANwS4PYEhLV2vTFmPvAljsqwNCJsxqgx5g2gC1DPGLMHGAskAW8ZYwbi+ND7P788WzNFRUTCg1IuIiJhQgFdRCRMKKCLiIQJBXQRkTChgC4iEiYU0EVEwoQCuohImFBAFxEJE/8Pjp+P6EBiTbIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1e76c8ab978>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#异质\n",
    "from ml_models.linear_model import LinearRegression\n",
    "model=GradientBoostingRegressor(base_estimator=[LinearRegression(),CARTRegressor(),CARTRegressor()])\n",
    "model.fit(data,target)\n",
    "plt.scatter(data, target)\n",
    "plt.plot(data, model.predict(data), color='r')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
